package l1j.opqlo.NewSystem;

import java.util.HashMap;

import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_NPCTalkReturn;
import l1j.server.server.utils.Random;

public class NewLaBa {
	private int s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, s6 = 0, s7 = 0, s8 = 0,
			s9 = 0;

	private final HashMap<Integer, String> _value = new HashMap<Integer, String>();

	public NewLaBa() {
		if (this._value.isEmpty()) {
			this._value.put(1, "１");
			this._value.put(2, "２");
			this._value.put(3, "３");
			this._value.put(4, "４");
			this._value.put(5, "５");
			this._value.put(6, "６");
			this._value.put(7, "７");
			this._value.put(8, "８");
			this._value.put(9, "９");
		}
	}

	public void NewLaBaStart(final L1PcInstance pc) {

		final int pcid = pc.getId();

		/*
		 * while(pc==null){ if(RunCount==0){ System.out.println("迴圈開始:"); } try
		 * { Thread.sleep(10); } catch (InterruptedException e) { // TODO
		 * Auto-generated catch block e.printStackTrace(); }
		 */
		for (int i = 0; i < 10; i++) {

			this.s1 = Random.nextInt(5) + 4;
			if (this.s1 == 7) {
				this.s1 = Random.nextInt(5) + 4;
			}

			this.s2 = Random.nextInt(5) + 4;
			if (this.s2 == 7) {
				this.s2 = Random.nextInt(5) + 4;
			}

			this.s3 = Random.nextInt(5) + 4;
			if (this.s3 == 7) {
				this.s3 = Random.nextInt(5) + 4;
			}

			this.s4 = Random.nextInt(5) + 4;
			if (this.s4 == 7) {
				this.s4 = Random.nextInt(5) + 4;
			}

			this.s5 = Random.nextInt(5) + 4;
			if (this.s5 == 7) {
				this.s5 = Random.nextInt(5) + 4;
			}

			this.s6 = Random.nextInt(5) + 4;
			if (this.s6 == 7) {
				this.s6 = Random.nextInt(5) + 4;
			}

			this.s7 = Random.nextInt(5) + 4;
			if (this.s7 == 7) {
				this.s7 = Random.nextInt(5) + 4;
			}

			this.s8 = Random.nextInt(5) + 4;
			if (this.s8 == 7) {
				this.s8 = Random.nextInt(5) + 4;
			}

			this.s9 = Random.nextInt(5) + 4;
			if (this.s9 == 7) {
				this.s9 = Random.nextInt(5) + 4;
			}

			final String msg[] = { this._value.get(this.s1),
					this._value.get(this.s2), this._value.get(this.s3),
					this._value.get(this.s4), this._value.get(this.s5),
					this._value.get(this.s6), this._value.get(this.s7),
					this._value.get(this.s8), this._value.get(this.s9) };

			try {
				Thread.sleep(80);
			} catch (final InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			pc.sendPackets(new S_NPCTalkReturn(pcid, "haha", msg));
		}

		int count = 0;
		if (this.s5 == this.s2 && this.s5 == this.s8) { // 中間一直線
			count++;
		}
		if (this.s5 == this.s4 && this.s5 == this.s6) {// 中間一橫線
			count++;
		}
		if (this.s5 == this.s1 && this.s5 == this.s9) {// 左斜線
			count++;
		}
		if (this.s5 == this.s3 && this.s5 == this.s7) {// 右斜線
			count++;
		}
		if (this.s1 == this.s2 && this.s2 == this.s3) { // 上橫線
			count++;
		}
		if (this.s1 == this.s4 && this.s4 == this.s7) { // 左直線
			count++;
		}
		if (this.s3 == this.s6 && this.s6 == this.s9) { // 右直線
			count++;
		}
		if (this.s7 == this.s8 && this.s8 == this.s9) {// 下橫線
			count++;
		}
		/*
		 * RunCount++; AllBet+=10; switch(count){ case 1: Count1++; AllBet-=10;
		 * break; case 2: Count2++; AllBet-=20; break; case 3: Count3++;
		 * AllBet-=100; break; case 4: Count4++; AllBet-=800; break; case 5:
		 * Count5++; AllBet-=2000; break; case 6: Count6++; AllBet-=(AllBet /4);
		 * break; case 7: Count7++; AllBet-=(AllBet /2); break; case 8:
		 * Count8++; AllBet-= AllBet; break; case 0: Count0++; break; }
		 */
		/*
		 * if(RunCount %1000 ==0){ final String st =
		 * "總次數:"+RunCount+"\r\n1連線:"+Count1
		 * +"\r\n2連線:"+Count2+"\r\n3連線:"+Count3+"\r\n4連線:"+Count4
		 * +"\r\n5連線:"+Count5
		 * +"\r\n6連線:"+Count6+"\r\n7連線:"+Count7+"\r\n8連線:"+Count8;
		 * System.out.println(st);
		 * System.out.println("▇▇▇▇▇▇▇▇▇總彩金累積"+AllBet+"▇▇▇▇▇▇▇▇▇");
		 * OtherXX.LogSave(19, st); }
		 */
		final String msg1[] = { this._value.get(this.s1),
				this._value.get(this.s2), this._value.get(this.s3),
				this._value.get(this.s4), this._value.get(this.s5),
				this._value.get(this.s6), this._value.get(this.s7),
				this._value.get(this.s8), this._value.get(this.s9),
				Integer.toString(count) };
		pc.sendPackets(new S_NPCTalkReturn(pcid, "haha", msg1));
		final StringBuffer bu = new StringBuffer().append("1").append("2")
				.append("3").append("4").append("5");
		bu.charAt(0);

	}

	// }

	// public int RunCount =0,Count0=0, Count1 =0, Count2 =0, Count3 =0, Count4
	// =0, Count5 =0, Count6 =0, Count7 =0, Count8 =0
	// , AllBet=0;

}
